package gsms

import (
	"github.com/aliyun/alibaba-cloud-sdk-go/sdk"
	"github.com/aliyun/alibaba-cloud-sdk-go/sdk/requests"
	"github.com/aliyun/alibaba-cloud-sdk-go/sdk/responses"
)

type Sms struct {
	Client  *sdk.Client
	Request *requests.CommonRequest
}

func NewSms(regionId, accessKeyId, accessKeySecret string) *Sms {
	client, _ := sdk.NewClientWithAccessKey(regionId, accessKeyId, accessKeySecret)

	return &Sms{
		Client:  client,
		Request: requests.NewCommonRequest(),
	}
}

// 设置参数
func (s *Sms) SetParams(content map[string]string) {
	s.Request.Domain = "dysmsapi.aliyuncs.com"
	s.Request.Version = "2017-05-25"
	s.Request.ApiName = "SendSms"

	s.Request.QueryParams["PhoneNumbers"] = content["to"]
	s.Request.QueryParams["SignName"] = content["signName"]
	s.Request.QueryParams["TemplateCode"] = content["templatecode"]
	s.Request.QueryParams["TemplateParam"] = content["templateParams"]
}

// 发起请求
func (s *Sms) Send() (response *responses.CommonResponse, err error) {
	response, err = s.Client.ProcessCommonRequest(s.Request)
	return
}
